//
//  MLWSearchViewController.m
//  KITCHEN_STORIES
//
//  Created by dllo on 16/6/6.
//  Copyright © 2016年 MLW. All rights reserved.
//

#import "MLWSearchViewController.h"
#import "MLWSearchOneViewController.h"
#import "MLWSearchModel.h"
@interface MLWSearchViewController ()<UISearchBarDelegate, LXSearchDelegate>

/** 数据源数组 */
@property (nonatomic, retain) NSMutableArray *datasourceArray;

@end

@implementation MLWSearchViewController

- (void)dealloc
{
    [self.searchBar release];
    
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.datasourceArray = [NSMutableArray array];
    
    //初始化自定义的搜索框:
    self.searchBar = [[MLWSearchBar alloc] initWithFrame:CGRectMake((ScreenWidth - 300) / 4, 5, 300, 31) cornerRadius:15 borderWidth:0 backgroundColor:[UIColor whiteColor] borderColor:[UIColor whiteColor]];
    
    //设置代理人:
    self.searchBar.LXSearchDelegate = self;
   
    
    //将搜索框加在导航栏上:
    [self.navigationController.navigationBar addSubview:self.searchBar];
    
    [self.searchBar release];
    
    
    
    
}


//协议方法:
- (void)beginSearchWithString:(NSString *)string
{
    //在这里进行数据请求*************************
    
    [MLWNetTool GetNetWithUrl:@"http://121.41.103.24/public/getRecipeHomeData.shtml" body:nil header:nil response:MLWJSON success:^(id result) {
        
        NSDictionary *dicME = (NSDictionary *)result;
        NSMutableArray *arrayList = [dicME objectForKey:@"list"];
        for (NSDictionary *dicList in arrayList) {
            
            MLWSearchModel *model = [[MLWSearchModel alloc] initWithDic:dicList];
            
            [self.datasourceArray addObject:model];
            [model release];
        }
        MLWSearchOneViewController *seaVC = [[MLWSearchOneViewController alloc] init];
        seaVC.arrayN = self.datasourceArray;
        
        [self.navigationController pushViewController:seaVC animated:YES];
        
        NSLog(@"%@", seaVC.arrayN);
        [seaVC release];
        
    } failure:^(NSError *error) {
        NSLog(@"请求失败");
    }];


    
    
   
    
}

//点击self.view 回收键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end


